package com.lv.dhart.presenter;


import com.lv.dhart.api.bean.HomeHDListBean;
import com.lv.dhart.api.bean.NoTiceListBean;
import com.lv.dhart.base.BasePresenter;
import com.lv.dhart.beans.JJHoldStockListBeans;
import com.lv.dhart.beans.cost.AddResultBean;
import com.lv.dhart.beans.login.LoginBean;
import com.lv.dhart.callback.cost.ICostAddCallback;
import com.lv.dhart.callback.IJJHoldStockListCallback;
import com.lv.dhart.callback.ILoginCallback;
import com.lv.dhart.manager.RetrofitManager;

import java.util.HashMap;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class JJHoldStockListPresenter extends BasePresenter {

    public void getJJHoldStockList(int offset, int limit, HashMap<String, String> params, IJJHoldStockListCallback callback) {
        RetrofitManager.getRetrofitManager()
                .getApiService()
                .getJJHoldStockList(offset, limit, params)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<JJHoldStockListBeans>() {
                    @Override
                    public void onSubscribe(Disposable disposable) {

                    }

                    @Override
                    public void onNext(JJHoldStockListBeans jjHoldeBeans) {
                        callback.onIJJHoldStockListSuccess(jjHoldeBeans);
                    }


                    @Override
                    public void onError(Throwable throwable) {
                        callback.onIJJHoldStockListFailure(throwable);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void login(HashMap<String, String> params, ILoginCallback callback) {
        RetrofitManager.getRetrofitManager()
                .getApiService()
                .login(params)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<LoginBean>() {
                    @Override
                    public void onSubscribe(Disposable disposable) {

                    }

                    @Override
                    public void onNext(LoginBean loginBean) {
                        callback.onLoginSuccess(loginBean);
                    }

                    @Override
                    public void onError(Throwable throwable) {
                        callback.onLoginError(throwable);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void addCostStockCode(HashMap<String, String> params, ICostAddCallback callback) {
        RetrofitManager.getRetrofitManager()
                .getApiService()
                .addCostStockCode(getToken(), params)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<AddResultBean>() {
                    @Override
                    public void onSubscribe(Disposable disposable) {

                    }

                    @Override
                    public void onNext(AddResultBean addResultBean) {
                        callback.onCostAddSuccess(addResultBean);
                    }

                    @Override
                    public void onError(Throwable throwable) {
                        callback.onCostAddFailure(throwable);
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getHomeHTList() {
        RetrofitManager.getRetrofitManager()
                .getApiService()
                .HomeHDList()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<HomeHDListBean>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull HomeHDListBean homeRXListBean) {
                        view.SUCCESS(homeRXListBean);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getNotice() {
        RetrofitManager.getRetrofitManager()
                .getApiService()
                .NoTiceList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NoTiceListBean>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull NoTiceListBean noTiceListBean) {
                        if (noTiceListBean != null) {
                            view.SUCCESS(noTiceListBean);
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        view.Error(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
